#include <cppunit/extensions/HelperMacros.h>
#include <cppunit/extensions/TestFactoryRegistry.h>
#include <cppunit/ui/text/TestRunner.h>
#include <everest/odbc/Environment.h>
#include <stdio.h>
#include <iostream>

using namespace std;
using namespace NS_EVEREST;
using namespace NS_EVEREST::odbc;


class OdbcEnvironmetTester : public CppUnit::TestFixture
{
	CPPUNIT_TEST_SUITE(OdbcEnvironmetTester);
	CPPUNIT_TEST(test);
	CPPUNIT_TEST_SUITE_END();

public:
	OdbcEnvironmetTester() {

	}
	~OdbcEnvironmetTester() {}

	void setUp(){}
	void tearDown(){}

	void test();

protected:

};

CPPUNIT_TEST_SUITE_REGISTRATION(OdbcEnvironmetTester);


void OdbcEnvironmetTester::test()
{
	Environment env;
	CPPUNIT_ASSERT(env.getHandle() != SQL_NULL_HANDLE);

	DriverInfo *pDrvInfo = env.getDriverInfo(SQL_FETCH_FIRST);
	printf("First DriverInfo = %p\n", pDrvInfo);
	while ( pDrvInfo ) {
		const char * pszDesc = pDrvInfo->getDescription();
		printf("Driver: %s\n", pszDesc?pszDesc:"");
		int count = pDrvInfo->getAttribCount();
		for ( int i = 0; i < count; ++i) {
			String key, val;
			if ( pDrvInfo->getAttribute(i, key, val) ) {
				printf("\t%s = %s\n", key.c_str(), val.c_str());
			}
		}
		pDrvInfo = env.getDriverInfo(SQL_FETCH_NEXT);
	}
}

int main(int argc, char **argv)
{
	printf("HHH\n");
	CppUnit::TextUi::TestRunner runner;
	CppUnit::TestFactoryRegistry &reg = CppUnit::TestFactoryRegistry::getRegistry();
	runner.addTest(reg.makeTest());
	printf("HHH2\n");
	return !runner.run();
}
